package com.spdb.spdbfl.utils;

import com.mysql.jdbc.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class CommonUtil {
    private static final Random random = new Random();

    /**
     * 随机名称
     *
     * @param key
     * @return
     */
    public static String getRandomName(String key) {
        Date data = new Date();
        SimpleDateFormat ft = new SimpleDateFormat("yyyyMMddHHmmss");

        String randomName = key + ft.format(data);
//        System.out.println("randomName:"+randomName);
        return randomName;
    }

    /**
     * 随机数字
     *
     * @return
     */
    public static int getRandomNum() {
        int random = (int) (100000000 + Math.random() * (999999999 - 100000000) + 1);
        System.out.println(random);
        return random;
    }

    /**
     * 随机手机号
     *
     * @return
     */
    public static String getRandomPhoneNumber() {
        return "13" + random.nextInt(9) + random.nextInt(9) + random.nextInt(9) + random.nextInt(9) + random.nextInt(9) + random.nextInt(9) + random.nextInt(9) + random.nextInt(9) + random.nextInt(9);
    }

    public static boolean isPrintSql() {
        boolean result = true;
        String v = ConfigProperty.getProperty("isPrintSql");
        if (!StringUtils.isNullOrEmpty(v) && v.toLowerCase().equals("false")) {
            result = false;
        }
        return result;
    }

    /**
     * 获取当前时间
     * @return
     */
    public static String getCurrentTime(){
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String format = sdf.format(date);
        return format;
    }


    public static void main(String[] args) {
        getRandomNum();
    }
}
